import request from '@/config/axios'

export type ProcessDefinitionVO = {
  id: string
  key: string
  name: string
  category: string
  version: number
  deploymentTIme: string
  suspended: boolean
  formType?: number
}

export type ModelVO = {
  id: string
  key: string
  name: string
  category: string
  icon: string
  description: string
  type: number
  visible: boolean
  startUserIds: string[]
  manageUserIds: string[]
  formType: number
  formId: number
  formCustomCreatePath: string
  formCustomViewPath: string
  allowCancelRunningProcess: boolean
  processIdRule: any
  autoApprovalType: number
  titleSetting: any
  summarySetting: any
  processBeforeTriggerSetting: any
  processAfterTriggerSetting: any
  bpmnXml: string
  sort: number
  createTime: string

  categoryName: string
  formName: string
  startUsers: any
  processDefinition: ProcessDefinitionVO
}

// BPM流程模型 API
export const ModelApi = {
  // 获取BPM流程模型分页
  getModelPage: async (params: PageParam) => {
    return await request.get({ url: `/bpm/model/page`, params })
  },

  // 获取BPM流程模型详情
  getModel: async (id: string) => {
    return await request.get({ url: `/bpm/model/get`, params: { id } })
  },

  // 新增BPM流程模型
  createModel: async (data: ModelVO) => {
    return await request.post({
      url: `/bpm/model/create`,
      data,
      extension: {
        ignoreRepeatCheck: true
      }
    })
  },

  // 修改BPM流程模型
  updateModel: async (data: ModelVO) => {
    return await request.post({
      url: `/bpm/model/update`,
      data,
      extension: {
        ignoreRepeatCheck: true
      }
    })
  },

  // 删除BPM流程模型
  deleteModel: async (id: string) => {
    return await request.delete({ url: `/bpm/model/delete`, params: { id } })
  },

  // 清理BPM流程模型
  cleanModel: async (id: string) => {
    return await request.delete({ url: `/bpm/model/clean`, params: { id } })
  },

  // 修改BPM流程模型状态
  updateModelStatus: async (id: string, status: number) => {
    return await request.post({ url: `/bpm/model/update-status`, data: { id, status } })
  },

  // 修改BPM流程模型bpmn
  updateModelBpmn: async (id: string, bpmnXml: string) => {
    return await request.post({ url: `/bpm/model/update-bpmn`, data: { id, bpmnXml } })
  },

  // 部署BPM流程模型
  deployModel: async (id: string) => {
    return await request.post({ url: `/bpm/model/deploy`, params: { id } })
  },

  updateModelSortBatch: async (ids: string[]) => {
    return await request.post({ url: '/bpm/model/update-sort-batch', data: { ids } })
  }
}
